import request from '../utils/request'

// 问卷类型定义
export interface Questionaire {
  questionaireId: number
  title: string
  introduction: string
  questionNum: number
}

// 问题类型定义
export interface Question {
  questionId: number
  questionaireId: number
  content: string
  optionText1: string
  optionText2: string
  optionText3: string
  optionText4: string
}

// 获取问卷列表
export const getQuestionaireList = () => {
  return request<{
    code: string
    msg: string
    total: number
    data: Questionaire[]
  }>({
    url: '/questionaire/list',
    method: 'get'
  })
}

// 获取问卷详情（包含题目）
export const getQuestionaireDetail = (questionaireId: number) => {
  return request<{
    code: string
    msg: string
    total: number
    data: {
      questionaire: Questionaire
      questions: Question[]
    }
  }>({
    url: `/questionaire/detail/${questionaireId}`,
    method: 'get'
  })
}

// 提交问卷答案
export const submitQuestionaireAnswer = (data: {
  questionaireId: number
  userId: number
  answers: {
    questionId: number
    selectedOption: number
  }[]
}) => {
  return request({
    url: '/questionaire/submit',
    method: 'post',
    data
  })
}

// 获取问卷问题
export const getQuestionaireQuestions = (questionaireId: number) => {
  return request({
    url: `/question/${questionaireId}/questions`,
    method: 'get'
  })
}

// 提交问卷答案
export const submitQuestionaireAnswers = (data: {
  userId: number
  questionaireId: number
  answers: number[]
}) => {
  return request({
    url: '/questionnaire/submit',
    method: 'post',
    data
  })
}
